﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Controls;
using MMK.Paket_Tracker.Runtime.BusinessEntities;
using MMK.Paket_Tracker.Runtime.Interfaces;
using MMK.Paket_Tracker.Runtime.Helper;
using System.Windows;

namespace MMK.Paket_Tracker.Runtime
{
    /// <summary>
    /// Base class for ViewModels
    /// </summary>
    public class ViewModelBase : INotifyPropertyChanged
    {
        /// <summary>
        /// Raises the property changed event.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

        /// <summary>
        /// Notifies the main window.
        /// </summary>
        /// <param name="windowNotification">The window notification.</param>
        protected void NotifyMainWindow(MainWindowNotification windowNotification)
        {
            FrameworkElement mainWindow;
            mainWindow = WPFTools.FindParentByName(owner,"StartupWindow");
            ((IMainWindowNotification)mainWindow).NotifyMainWindow = windowNotification;
        }

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        /// Protected variable to hold the owner of the ViewModel
        /// </summary>
        protected UserControl owner;
    }

}
